<%--
  Created by IntelliJ IDEA.
  User: Master
  Date: 30.03.2011
  Time: 19:48:41
  To change this template use File | Settings | File Templates.
--%>
<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.transcargo.data.CountriesData" %>
<%@ page import="com.transcargo.geo.Country" %>
<%@ page import="com.transcargo.geo.Region" %>
<%@ page import="com.transcargo.geo.City" %>
<%@ page import="java.util.Date" %>
<%@include file="header.jsf"%>
<%@include file="session.jsf"%>
<%@include file="resolve_country.jsf"%>
<%
	Country[] countries = CountriesData.getCountries(dbase);

%>
<html>
  	<head><title>TransCargo</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="forms.js"></script>
	<link type="text/css" href="transcargo.css" rel="stylesheet"/>
  </head>
  <body>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr><td colspan="2">
			<%@include file="page_header.jsf"%>
        </td></tr>
        <tr><td width="80%" align="center">
            <table width="100%" cellpadding="0" cellspacing="0">
	            <tr><td align="center"><h1>ТрансКарго</h1></td></tr>
	            <tr><td align="center"><center>Поиск по странам</center>
                    <table border="0">
                        <tr><th>Страна</th><th>Транспорт</th><th>Грузы</th></tr>
                    <%
                        int freight = 0, cargo = 0;
                        for (int i = 0; i < countries.length; i++) {
                            Country c = countries[i];
                            list = dbase.execute("SELECT count(id) FROM posted_transport WHERE (date_load<=CURRENT_DATE AND date_unload>=CURRENT_DATE) OR permanent=1 AND visible=1 AND (country_id_from=" + c.getId() + " OR country_id_to=" + c.getId() + ")");
                            iter = list.iterator();
                            String[] res = iter.next();
                            freight = Integer.parseInt(res[0]);
                            list = dbase.execute("SELECT count(id) FROM posted_cargo WHERE (date_load<=CURRENT_DATE AND date_unload>=CURRENT_DATE) OR permanent=1 AND visible=1 AND (country_id_from=" + c.getId() + " OR country_id_to=" + c.getId() + ")");
                            iter = list.iterator();
                            res = iter.next();
                            cargo = Integer.parseInt(res[0]);
                            %>
                        <tr><td><%=c.getName()%></td><td><a href="country_freight.jsp?cid=<%=c.getId()%>"><%=freight%></a></td><td><a href="country_cargo.jsp?cid=<%=c.getId()%>"><%=cargo%></a></td></tr>
                            <%
                        }
                    %>
                    </table>
            </td></tr></table>
        </td><td valign="top"><%@include file="login.jsf"%><br><%@include file="quicksearch.jsf"%></td></tr>
    </table>
  </body>
</html>
